package Month10;

public class sqstack
{
    private static final int MAXSIZE = 10;
    private int top;
    private char[] data;

    //1初始化
    public sqstack()
    {
        top = -1;
        data = new char[MAXSIZE];
    }

    //2判断空不空
    public boolean isEmpty()
    {
        if (top == -1)
        {
            return true;
        }
        return false;
    }

    //3进栈
    public boolean intoStack(char[] arr)
    {

        for (int i = 0; i < arr.length; i++)
        {
            if (top == MAXSIZE - 1)
            {
                return false;
            }
            data[top + 1] = arr[i];
            top++;
        }
        return true;

    }

    //4出栈
    public boolean outStack(int n)
    {
        if (n <= 0)
            return false;
        for (int i = n; i > 0; i--)
        {
            if (top == -1)
            {
                return false;
            }
            System.out.println(data[top] + "出栈");
            data[top + 1] = ' ';
            top--;
        }
        return true;
    }
}
